/*

*/
#include "GRAVITY.h"

GRAVITY::GRAVITY()
{
	//default constructor
	G = 6.67428e-11;
	lbtokg = 2.2;
	

}
void GRAVITY::askW()
{
	double weigh;
	cout << "Please enter your weight in pounds: ";
	cin >> weigh;
	 weight = weigh;

}
void GRAVITY::interfaceG()
{
		char *names[] =
	{
		"SOL (the sun)",
		"Moon",
		"Mars",
		"Jupiter"
	};
		double mass[]=
		{
			1.991e30,
			7.36e22,
			6.42e23,
			1.90e27
		};
		double radius[] =
		{
			6.96e8,
			1.74e6,
			3.37e6,
			6.99e7
		};
	askW();
	clearscreen();
	int choice;
	cout << "Please select the desired option" << endl;
	cout << "0. Enter custom information" << endl;
	for(int num = 1;num <= (sizeof(names)/sizeof(*names));num++)
	{
		cout << num <<". My weight on the "<<names[num-1]<<endl;
	}
	cout << "5. Calculate my mass" << endl;
	cout << "6. Calculate my force of gravity" << endl;
	/*cout << "1. My weight on the SUN"<<endl;
	cout << "2. My weight on the MOON"<<endl;
	cout << "3. My weight on the MARS"<<endl;
	cout << "4. My weight on the JUPITER"<<endl;
	*/
	cin >> choice;
	clearscreen();
	if(choice == 0)
	{
		createcustom();
	}
	else if(choice == 1)
		{	
		interact("SOL (the sun)",calcW(convertWtoM(convertW(weight)),calcFG(mass[0],radius[0])));
		
		}	
	else if(choice == 2)
	{
	
		interact("The Moon",calcW(convertWtoM(convertW(weight)),calcFG(mass[1],radius[1])));
	}
	
	else if(choice == 3)
	{
		interact("Mars",calcW(convertWtoM(convertW(weight)),calcFG(mass[2],radius[2])));
	}
	else if(choice == 4)
	{
		interact("Jupiter",calcW(convertWtoM(convertW(weight)),calcFG(mass[3],radius[3])));
	}
	else if(choice == 5)
	{
		cout << "Your mass based on the weight you entered is approximately "<< convertWtoM(convertW(weight)) <<" Kilograms"<< endl;
	}else if(choice == 6)
	{
		askH();
		cout << "Your Force of gravity is "<< calcFG(convertWtoM(convertW(weight)),getH()/2) << endl;
	}
	/*
	int mnumber = 0;
	while(mnumber < (sizeof(mass)/sizeof(*mass)))//creates our names in a link list
	{
		lmass.push_back(mass[mnumber]);
		mnumber++;
	}
	int rnumber = 0;
	while(rnumber < (sizeof(radius)/sizeof(*radius)))//creates our names in a link list
	{
		radii.push_back(radius[rnumber]);
		rnumber++;
	}
	int number =0;
	while(number < (sizeof(names)/sizeof(*names)))//creates our names in a link list
	{
		celestialname.push_back(names[number]);
		number++;
	}
	while(!celestialname.empty())
	{
		cout << celestialname.front()<<" "<< lmass.front()<< " "<< radii.front() << endl;
		celestialname.pop_front();
		radii.pop_front();
		lmass.pop_front();
	}
	*/
}
void GRAVITY::interact(string name,double weight) //displays the results
{
	cout << "Your weight on "<< name <<" is " << weight <<" kilograms or "<< weight*lbtokg <<" pounds."<<endl;
}
void GRAVITY::clearscreen()
{
	HANDLE                     hStdOut;
  CONSOLE_SCREEN_BUFFER_INFO csbi;
  DWORD                      count;
  DWORD                      cellCount;
  COORD                      homeCoords = { 0, 0 };

  hStdOut = GetStdHandle( STD_OUTPUT_HANDLE );
  if (hStdOut == INVALID_HANDLE_VALUE) return;

  /* Get the number of cells in the current buffer */
  if (!GetConsoleScreenBufferInfo( hStdOut, &csbi )) return;
  cellCount = csbi.dwSize.X *csbi.dwSize.Y;

  /* Fill the entire buffer with spaces */
  if (!FillConsoleOutputCharacter(
    hStdOut,
    (TCHAR) ' ',
    cellCount,
    homeCoords,
    &count
    )) return;

  /* Fill the entire buffer with the current colors and attributes */
  if (!FillConsoleOutputAttribute(
    hStdOut,
    csbi.wAttributes,
    cellCount,
    homeCoords,
    &count
    )) return;

  /* Move the cursor home */
  SetConsoleCursorPosition( hStdOut, homeCoords );
}
void GRAVITY::createcustom()//allows you add your own objects to test :) 
{
	
	string name;
	double mass;
	double radius;
	cout << "Please enter the name" << endl;
	cin >> name;
	clearscreen();
	cout << "Please enter the mass" << endl;
	cin >> mass;
	clearscreen();
	cout << "please enter the radius" <<endl;
	cin >> radius;
	clearscreen();
	interact(name,calcW(convertWtoM(convertW(weight)),calcFG(mass,radius)));
	
}
void GRAVITY::askH()// asks for your height
{
	double h;
	cout << "Please enter your height" << endl;
	cin >> h;
	setH(h*.0254);
}
double GRAVITY::calcFG(double mass,double radius)//calculates force of gravity
{
	return G*mass/(radius*radius);
}
double GRAVITY::convertW(double pounds)//returns weight converted into kilograms
{
	return pounds/lbtokg;
}
double GRAVITY::convertWtoM(double kilograms)//returns mass based on your weight / the force of earths gravity
{
	return kilograms/calcFG(5.98e24,6.37e6);
}
double GRAVITY::calcW(double mass,double fg)
{
	return mass*fg;
}
